package com.hainiu.cat.sort.write;

import com.hainiu.cat.util.SortUtil;

/**
 * create by biji.zhao on 2021/5/31
 */
public class BubbleSort {

    public static void main(String[] args) {
        int [] nums = {1, 3, 5, 10, 30, 28, 3, 17};

        SortUtil.arrayToString(nums);

        sorting(nums);

        SortUtil.arrayToString(nums);
    }

    private static void sorting(int[] nums) {
        int i = 1;
        while (i < nums.length - 1) {
            for (int j = 0; j <= nums.length - 2; j++) {
                if (nums[j] > nums[j + 1]) {
                    SortUtil.swap(nums, j , j + 1);
                }
            }
            i ++;
        }
    }
}
